<?php

/**
 * This is the model class for table "xman_user_skill".
 *
 * The followings are the available columns in table 'xman_user_skill':
 * @property integer $user_skill_id
 * @property integer $user_skill_user_id
 * @property integer $user_skill_skill_id
 * @property integer $skill_level
 * @property integer $experience_year
 * @property string $user_skill_description
 *
 * The followings are the available model relations:
 * @property User $userSkillUser
 * @property Skill $userSkillSkill
 */
class UserSkill extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return UserSkill the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'xman_user_skill';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('user_skill_user_id, user_skill_skill_id, skill_level, experience_year', 'required'),
			array('user_skill_user_id, user_skill_skill_id, skill_level, experience_year', 'numerical', 'integerOnly'=>true),
			array('user_skill_description', 'length', 'max'=>100),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('user_skill_id, user_skill_user_id, user_skill_skill_id, skill_level, experience_year, user_skill_description', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'userSkillUser' => array(self::BELONGS_TO, 'User', 'user_skill_user_id'),
			'userSkillSkill' => array(self::BELONGS_TO, 'Skill', 'user_skill_skill_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'user_skill_id' => 'User Skill',
			'user_skill_user_id' => 'User Skill User',
			'user_skill_skill_id' => 'User Skill Skill',
			'skill_level' => 'Skill Level',
			'experience_year' => 'Experience Year',
			'user_skill_description' => 'User Skill Description',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('user_skill_id',$this->user_skill_id);
		$criteria->compare('user_skill_user_id',$this->user_skill_user_id);
		$criteria->compare('user_skill_skill_id',$this->user_skill_skill_id);
		$criteria->compare('skill_level',$this->skill_level);
		$criteria->compare('experience_year',$this->experience_year);
		$criteria->compare('user_skill_description',$this->user_skill_description,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}